package com.voole.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.mapping.StatementType;
import org.springframework.stereotype.Repository;

import com.voole.entity.SysAuthority;
import com.voole.entity.SysRoleAction;
import com.voole.entity.SysUser;
import com.voole.entity.SysUserRole;

@Repository
public interface SysUserRoleDao {

	@Insert("INSERT INTO sys_user_role (`userid`, `roleid`) VALUES (#{userid}, #{roleid})")  
	@Options(useGeneratedKeys = true, keyProperty = "id")
	Integer addSysUserRole(SysUserRole sysUserRole);
	
	@Select(value="SELECT * FROM sys_user_role WHERE userid = ${userId}")
	List<SysUserRole> getList(@Param(value="userId")Integer userId);
	
	@Select(value="SELECT roleid FROM sys_user_role WHERE userid = ${userId}")
	List<Integer> getRoleIdList(@Param(value="userId")Integer userId);
	
	@Select(value="SELECT sr.name FROM sys_user_role sur LEFT JOIN sys_user su ON sur.userid = su.id LEFT JOIN sys_role sr ON sur.roleid = sr.id WHERE sur.userid = ${userId}")
	List<String> getRoleNameList(@Param(value="userId")Integer userId);
}